#{extends 'main.html' /}
#{set title:'Answer' /}

#{navigation /}

<div class="content">
		<div id="breadcrumb">
		<a href="@{Courses.index}">Courses</a> → <a href="@{Courses.show(lecture.course.id)}">${lecture.course.name}</a> → <a href="@{Lectures.show(lecture.id)}">${lecture.name}</a> → ${question.title}
	</div>
	
	<h1>${question.title}</h1>
	<span>
	${question.content}<br>
	</span>
	-- ${question.postedBy.name}
	
	<h2>Expert Answers</h2>
	#{list items:answers, as:'answer'}
		<span>
			${answer.postedAt.format('dd-mm-yyyy, hh:ss')}: <b>${answer.title}</b><br>
			${answer.content} <br>
			--- ${answer.postedBy.name}
			#{if answer.postedBy.name == user.name}<a href="@{Answers.deleteAnswer(question.id, answer.id)}">Delete</a>#{/if}<br>
			Positive: ${answer.getUpvoteCount()}<br>
			Negative: ${answer.getDownvoteCount()}<br>
			<a href="@{Votes.answerUpVote(answer.id)}">vote up</a> <a href="@{Votes.answerDownVote(answer.id)}">vote down</a>
		</span>
	#{/list}
	
	<h2>Comments</h2>
	#{list items:comments, as:'comment'}
		<span>
			${comment.postedAt.format('dd-mm-yyyy, hh:ss')}<br>
			${comment.content} <br>
			--- ${comment.postedBy.name}
			#{if comment.postedBy.name == user.name}<a href="@{Answers.deleteComment(question.id, comment.id)}">Delete</a>#{/if}<br><br>
		</span>
	#{/list}
	
	#{form @Answers.addComment(question.id)}
	<span id="comment-field">
			<label for="content">Posting as ${user.name}</label><br>
			<textarea type="text" name="content" id="content"></textarea><br>
			<input type="submit" id="submit" value="comment" />
			<br>
	</span>
	#{/form}
	
	#{if user.isExpert}
	#{form @Answers.addAnswer(question.id)}
	<span id="comment-field">
			<label>Answering as ${user.name}</label><br>
			<input type="text" name="title" id="title" value="title.."/><br>
			<textarea type="text" name="content" id="content"></textarea><br>
			<input type="submit" id="submit" value="answer" />
	</span>
	#{/form}
	#{/if}
</div>